/*
多线程倒数计数器
*/


#pragma once

#include <mutex>
#include <condition_variable>

class CountDownLatch
{

public:
    //explicit避免隐式类型转换
    explicit CountDownLatch(int count);
    //可以多线程同时调用wait()
    void wait();
    //倒数计数1
    void countDown();
    //获取当前计数
    int getCount() const;

private:

    //以下新添加,原版没有=delete
    CountDownLatch(const CountDownLatch& ) = delete;
    CountDownLatch& operator = (const CountDownLatch& ) = delete;

    //C++11互斥量
    mutable std::mutex      m_mutex;
    //C++11条件变量
    std::condition_variable m_condition;
    int                     m_count;
};